//
//  XJMainTabBarController.swift
//  XJWeiBO
//
//  Created by 452608533 on 16/7/19.
//  Copyright © 2016年 452608533. All rights reserved.
//

import UIKit

class XJMainTabBarController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        let tabBar = XJBottomTabBar()
        
        tabBar.xjBottomDelegate = self
        
        tabBar.closure = {
            
            let composeVc = XJComposeController()
            self.presentViewController(UINavigationController(rootViewController: composeVc), animated: true, completion: nil)

        }
        //给只读属性赋值 用KVC
        setValue(tabBar, forKey: "tabBar")
        
        //设置导航控制器
        addChildViewController(XJHomeViewController(), title: "首页", imgName: "tabbar_home")
        addChildViewController(XJMessageViewController(), title: "信息", imgName: "tabbar_message_center")
        addChildViewController(XJDiscoverViewController(), title: "发现", imgName: "tabbar_discover")
        addChildViewController(XJProfileController(), title: "我", imgName: "tabbar_profile")

    }

    func addChildViewController(vc: UIViewController, title: String, imgName: String) {
        
        vc.title = title;
        vc.tabBarItem.image = UIImage(named: imgName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        vc.tabBarItem.selectedImage = UIImage(named: "\(imgName)_selected")?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName: UIColor.orangeColor()], forState: UIControlState.Selected)
        
        addChildViewController(UINavigationController(rootViewController: vc))
    }
}

extension XJMainTabBarController :XJBottomTabBarDelegate{
    
    func didClickComposeButton() {
        
        print("点击撰写按钮")

    }
}
